<template>
  <div class="app-container">
    <!-- <template v-if="globalAdmin">
      <ht-search-form
        :dictMap="dictMap"
        :queryParams="queryParams"
        :outputQueryParams="queryParams"
        :formOptions="formOptions"
        :advOptions="[]"
        permission="user:tenantInfo:view"
      ></ht-search-form>
    </template> -->

    <ht-table
      ref="dataTable"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="reqConfig"
    >
    </ht-table>

    <Add ref="addDialog" @editComplete="changeTypeInfoOpen" />
  </div>
</template>

<script>
import {
  apiUrlConfig,
  delMenu,
} from "@/api/authority_app/favouriteMenu/index.js";
import { listPageMixin } from "@/libs/listPageMixin";
import Add from "@/views/system/favouriteMenu/components/add";
import { mapGetters } from "vuex";

export default {
  name: "loginInfo",
  mixins: [listPageMixin],
  components: {
    Add,
  },
  computed: {
    ...mapGetters(["globalAdmin"]),
  },
  data() {
    return {
      // 查询参数
      queryParams: {},
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: `${this.lang("common.add")}`,
            type: "primary",
            icon: "el-icon-plus",
            // permission: "user:favouriteMenu:add",
            clickFun: () => {
              this.handleAction("add");
            },
          },
        ];
      },
      reqConfig: apiUrlConfig,
      // 列信息
      tableBindColumns: [
        {
          label: this.$t("authority.favouriteMenu.form.menu"),
          prop: "menuName",
        },
        {
          label: this.$t("common.remark"),
          prop: "remark",
        },
        {
          label: this.$t("common.createTime"),
          prop: "createTime",
        },
        {
          label: `${this.lang("common.operate")}`,
          type: "operate",
          buttonList: (rowData) => [
            {
              label: `${this.lang("common.delete")}`,
              permission: "user:favouriteMenu:remove",
              doFunc: (rowData) => {
                this.handleAction("del", rowData);
              },
            },
          ],
        },
      ],
      // 表单参数
      form: {},
      // 子项目表单
      formChild: {},
    };
  },
  methods: {
    //一级弹窗状态修改
    changeTypeInfoOpen(state) {
      if (state) {
        this.doQuery();
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id || this.ids;
      this.$confirm(this.$t("validate.sureDelete"), this.$t("common.warning"), {
        confirmButtonText: this.$t("common.confirm"),
        cancelButtonText: this.$t("common.cancel"),
        type: "warning",
      })
        .then(function () {
          return delMenu(id);
        })
        .then(() => {
          this.doQuery();
          this.msgSuccess(this.$t("common.deleteSuccess"));
        })
        .catch((action) => {});
    },
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "add":
          this.$refs.addDialog.show("", true);
          break;
        case "del":
          this.handleDelete(row);
          break;
      }
    },
  },
};
</script>
